/* @(#)GSOrderQueryConfirmAction.java    
 *
 * Project: GS
 *
 * Modify Information:
 * =============================================================================
 *   Author       Date       Description
 *   ------------ ---------- ---------------------------------------------------
 *   Jenny Li     2006-2-16    新增
 *
 * Copyright Notice:
 * =============================================================================
 *    Copyright (c) 2001-2006 Beijing HiTRUST Technology Co., Ltd. 1808 Room, 
 *        Science & Technology Building, No. 9 South Street, Zhong Guan Cun, 
 *        Haidian District, Beijing ,100081, China All rights reserved.
 *
 *    This software is the confidential and proprietary information of
 *        Beijing HiTRUST Technology Co., Ltd. ("Confidential Information").
 *        You shall not disclose such Confidential Information and shall use it
 *        only in accordance with the terms of the license agreement you entered
 *        into with HiTRUST.
 *
 * Warning:
 * =============================================================================
 * 
 */
package com.hitrust.gs.action;

import java.util.ArrayList;

import system.LoginContext;

import com.hitrust.gs.business.GSOrderProcessor;
import com.hitrust.gs.business.GSUniteGwProcessor;
import com.hitrust.gs.form.GSOrderReceiveQueryForm;
import com.hitrust.gs.lib.GSBaseConstants;
import com.hitrust.gs.service.GSBaseAction;
import com.hitrust.gs.service.GSBaseForm;
import com.hitrust.gs.service.GSBaseManager;
import com.hitrust.gs.util.page.ResultProcess;
import com.hitrust.gs.vo.GSOrderVO;

/**
 * 
 */
public class GSOrderReceiveQueryAction extends GSBaseAction {

    public String execute(GSBaseForm aForm) throws Exception {
        
		GSOrderReceiveQueryForm tForm = (GSOrderReceiveQueryForm)aForm;
        
        //取得页面参数组成订单VO对象
        GSOrderVO tOrderVO = new GSOrderVO();
        tOrderVO.orderid = tForm.orderId;
		tOrderVO.orderDetailId = tForm.orderDetailId;
        tOrderVO.orderDetailStatus = tForm.orderDetailStatus;
        tOrderVO.orderDeptId = tForm.orderDeptId;
        tOrderVO.concentricityId = tForm.concentricityId;
        tOrderVO.manufInfo = tForm.manufInfo;
        tOrderVO.providerName = tForm.providerName;
        tOrderVO.orderCreateDateLowLimie = tForm.orderCreateDateStr;
        tOrderVO.orderCreateDateUprLimie = tForm.orderCreateDateEnd;
        tOrderVO.deliverGoodsId = tForm.deliverGoodsId;
        tOrderVO.drawingpcode=tForm.drawingpcode;
        
        try{

            //取得操作类型
            String tNeedExport = tForm.getNeedexport();

            //取得当前操作员信息
            LoginContext loginContext = (LoginContext)aForm.getSession().getAttribute(GSBaseConstants.LOGIN);
            GSUniteGwProcessor processer = new GSUniteGwProcessor();
            ArrayList ary = processer.getWareHouseLevelName(loginContext.getLoginWarehouseCode(),loginContext.getLoginWarehouseCode());
            aForm.getRequest().setAttribute("orderdept",ary);
            //取得分页参数
            String[] tStr = this.getPageParams(tForm,tOrderVO);
            //查询订单
            GSOrderProcessor tProc = new GSOrderProcessor();
            if(tNeedExport != null && tNeedExport.equals("yes")){
                GSOrderProcessor.getOrderDetailDownexcel(tForm,tOrderVO,1,6000);
            }
            ArrayList tList = tProc.getOrderDetailByOpt_r(tOrderVO,Integer.parseInt(tStr[0]),Integer.parseInt(tStr[1]));
            ResultProcess tRsProc = new ResultProcess();
            tRsProc.setResult(tList);
            tForm.getRequest().setAttribute("order",tRsProc);
            //存储分页参数
            tForm.getRequest().setAttribute("pageSize",tStr[1]);
            tForm.getRequest().setAttribute("totalRecords",tStr[2]);
        }catch(Exception e){
            tForm.getRequest().setAttribute("action","A101301.do");
            throw e;
        }
        return GSBaseConstants.FORWARD_SUCCESS;
    }
    /**
     * 取得分页参数
     * @param aForm         基类form
     * @param aOrderVO      订单VO
     * @param aOrg          组织ArrayList对象
     * @return
     * @throws Exception
     */
    private String[] getPageParams(GSBaseForm aForm,GSOrderVO aOrderVO) throws Exception{
        String tStr[] = new String[3];
        int totalRecords;
        int pageNo;
        int pageSize;
        String tPage = GSBaseConstants.tPage;
        GSOrderProcessor tProc = new GSOrderProcessor();
        //根据页面传入的查询参数查询订单信息
        if(aForm.getChoice() == null || aForm.getChoice().equals("")){
            totalRecords = tProc.getOrderDetailCountByOpt_r(aOrderVO);
            // 取得系统默认的页大小
            pageSize = Integer.parseInt(tPage);
            // PageNo=1
            pageNo = 1;
            int n = (totalRecords % pageSize == 0 )? totalRecords / pageSize:totalRecords / pageSize + 1;
            if (pageNo>n) {
                pageNo=n;
            }
            tStr[0] = "" + pageNo;
            tStr[1] = "" + pageSize;
            tStr[2] = "" + totalRecords;
        }else{
            tStr = GSBaseManager.getPageNoAndPageSize(aForm);
        }
        return tStr;
    }
}
